<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns="http://www.w3.org/1999/XSL/Format"
  exclude-result-prefixes="doc f">

  <xsl:import href="../../../style/base.xsl"/>
  
  <xsl:param name="image_content-width" select="'300%'"/>
  <!--xsl:param name="image_content-width" select="'scale-to-fit'"/-->
  
  <xsl:template match="doc:image">
    <xsl:variable name="src">
      <xsl:if test="not(starts-with(@ref,'/'))">
        <xsl:value-of select="f:object-id(.)" />
        <xsl:text>/../</xsl:text>
      </xsl:if>
      <xsl:value-of select="@ref" />
      <xsl:if test="not(matches(@ref,'\.[^/]+$'))">.png</xsl:if>
    </xsl:variable>
    <block text-align="center" margin-top="5mm" margin-bottom="0mm" margin-left="0.6cm" margin-right="0.6cm">
      <external-graphic src="{$src}" width="100%" content-width="{$image_content-width}" scaling="uniform"
        scaling-method="resample-any-method" />
    </block>
    <xsl:if test="normalize-space(doc:note) != ''">
      <block font-size="6pt" margin-left="0.6cm" text-align="center">
        <xsl:apply-templates select="doc:note/node()" />
      </block>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>
